Random Mobile Names HOWTO

Version 0.1
Written by Tarl

One of the additions we have made to the stock smaug codebase is the ability to
allow mobiles to have random names. This document aims to describe the methods
required to configure this on your copy of the AFKMud codebase.

Random mobile names will require code alterations, as well as the creation of
one or more files, the format of which will be described later.

Code Alterations:

In the AFKMud codebase, under the src directory you'll see the file roomindex.cpp

On approximately line 1171 you will see the following code snippet.

            /*
             * Added by Tarl 4 Dec 02 so that if a mob is 'flagged' namegen in
             * his name, it will auto assign a random name to it. Similarly,
             * occurrences of namegen in the long_descr and description will be
             * replaced with the name.
             */
            std::string namegenCheckString = ( !mob->name.empty() ? mob->name : "" );

            /*
             * Modified by Tarl 5 Dec 02 to add extra namegen options. ie, namegen_gr will pick a name
             * suitable for Graecian mobs.
             *
             * To add more, edit the line below this, and add an if-check similar to the one starting
             * with if( namegenCheckString.find( "namegen_gr" ) != string::npos )
             *
             * And then Samson shows up and cleans up the code, kills off the memory leaks, and life was good.
             * Or something like that anyway. Merry Christmas 2005!
             *
             * Samson shows up out of the blue 21 years later and overhauls the whole system to get rid of the icky C buffers. 6-1-2026.
             */
            std::string namegen_tag = "";
            std::filesystem::path file = "";

            if( namegenCheckString.find( "namegen_gr" ) != std::string::npos )
            {
               namegen_tag = "namegen_gr";
               file = std::format( "{}{}", SYSTEM_DIR, ( mob->sex == SEX_FEMALE ? "namegen_gr_female.txt" : "namegen_gr_other.txt" ) );
            }
            else if( namegenCheckString.find( "namegen_ven" ) != std::string::npos )
            {
               namegen_tag = "namegen_ven";
               file = std::format( "{}{}", SYSTEM_DIR, ( mob->sex == SEX_FEMALE ? "namegen_ven_female.txt" : "namegen_ven_other.txt" ) );
            }
            else if( namegenCheckString.find( "namegen_orc" ) != std::string::npos )
            {
               namegen_tag = "namegen_orc";
               file = std::format( "{}{}", SYSTEM_DIR, ( mob->sex == SEX_FEMALE ? "namegen_orc_female.txt" : "namegen_orc_other.txt" ) );
            }
            else if( namegenCheckString.find( "namegen" ) != std::string::npos )
            {
               namegen_tag = "namegen";
            }

            if( !namegen_tag.empty() )
            {
               std::string nameg = "";

               if( file.empty() )
               {
                  name_generator( nameg );
               }
               else
               {
                  pick_name( nameg, file );
               }

               std::string new_keywords = namegenCheckString + " " + nameg;
               mob->name = new_keywords;
               mob->short_descr = nameg;

               if( !mob->long_descr.empty() )
               {
                  std::string long_desc = mob->long_descr;
                  string_replace( long_desc, namegen_tag, nameg );
                  mob->long_descr = long_desc;
               }

               if( !mob->chardesc.empty() )
               {
                  std::string char_desc = mob->chardesc;
                  string_replace( char_desc, namegen_tag, nameg );
                  mob->chardesc = char_desc;
               }
            } // End Namegen code.


Most of the following instructions are documented as comments in the code, so feel free to skip over them
here if the code instructions are sufficient for you.

In order to add a new random mobile name section, you need to edit the if check shown above, and add a similar
option that is suitable for you. Please note that this string is required to start with namegen_
An example of adding a new section called namegen_example is shown below:

            if( namegenCheckString.find( "namegen_gr" ) != std::string::npos )
            {
               namegen_tag = "namegen_gr";
               file = std::format( "{}{}", SYSTEM_DIR, ( mob->sex == SEX_FEMALE ? "namegen_gr_female.txt" : "namegen_gr_other.txt" ) );
            }
            else if( namegenCheckString.find( "namegen_ven" ) != std::string::npos )
            {
               namegen_tag = "namegen_ven";
               file = std::format( "{}{}", SYSTEM_DIR, ( mob->sex == SEX_FEMALE ? "namegen_ven_female.txt" : "namegen_ven_other.txt" ) );
            }
            else if( namegenCheckString.find( "namegen_orc" ) != std::string::npos )
            {
               namegen_tag = "namegen_orc";
               file = std::format( "{}{}", SYSTEM_DIR, ( mob->sex == SEX_FEMALE ? "namegen_orc_female.txt" : "namegen_orc_other.txt" ) );
            }
            else if( namegenCheckString.find( "namegen" ) != std::string::npos )
            {
               namegen_tag = "namegen";
            }

Next, you will have to add an if check similar to the ones beginning with: if( namegenCheckString.find( "namegen_gr" ) != std::string::npos )

We base our random names on the sex of our mobiles, but you may choose to remove this check, or to alter it to
some other attribute. The important parts of the if check that are required are the following:

               namegen_tag = "namegen_ven";
               file = std::format( "{}{}", SYSTEM_DIR, ( mob->sex == SEX_FEMALE ? "namegen_ven_female.txt" : "namegen_ven_other.txt" ) );

namegen_ven_female.txt and namegen_ven_other.txt should be replaced with the filenames of your random names.
For more information on the format of this file, please see below.

That's all the code alterations that are required.

Random Name File Format

The random name file (used in the code as outlined above) should have the following format:

[start]
A
Ab
Ac
Ad
[middle]
a
ae
ae
au
ao
are
[end]
a
and
b
bwyn
[finish]

Any number (greater then zero) of word-parts can be contained between each of the []'d parts. Please note that ALL FOUR of the []'d parts
are required, or your MUD will most likely crash. :)

The word-parts are formed into names by randomly selecting one from each section. Based on the example file above, some sample names that
can be formed include: Abaeb, Adarebwyn, etc. (Obviously these aren't terribly good names, but it is somewhat of a limited example. A real
file would have many more combinations.)

This file should be located in the system/ directory.

That's it for the file format section.



Mobile Setup

In order to tell a mobile to utilize the random name code, mobs should be mset name namegen_example

Similarly, any occurrences of the word namegen (note that this should really be namegen, not namegen_example) in the short and long
descriptions of the mobile will be replaced with the mobiles new name.

That's it for the mobile setup section.

You should now have randomly named mobiles in your MUD.

Thank you for using the AFKMud codebase, and if you have any problems with either the codebase, or these directions, please feel free to
post on the forums located via https://smaugmuds.afkmods.com/

Tarl.

================

Samson here, in 2026:

The code currently has support written for the following filenames to generate region specific naming:

namegen_gr_female.txt
namegen_gr_other.txt
namegen_ven_female.txt
namegen_ven_other.txt
namegen_orc_female.txt
namegen_orc_other.txt

Unfortunately they have been lost to the dustbin of history. Or perhaps never existed. This name generation code was a feature
added to the codebase very late in development and didn't get much attention even then.

We are going to leave the code support for processing them in place in case you want to have a go at supporting this in your MUD.
